Skip to content

Don't disable AI prompt Save button when offline#92102

Open
MelvinBot wants to merge 7 commits into
mainfrom
claude-agentAIPromptOfflineSave
Open

Don't disable AI prompt Save button when offline#92102
MelvinBot wants to merge 7 commits into
mainfrom
claude-agentAIPromptOfflineSave

Conversation

@MelvinBot
Copy link
Copy Markdown
Contributor

@MelvinBot MelvinBot commented May 29, 2026

Explanation of Change

When the agent's AI prompt Save button was tapped while offline, updateAgentPrompt's optimistic data set pendingAction = UPDATE, which made isSaving permanently true (the API call could not resolve while offline) — leaving the button stuck in its loading/disabled state until reconnect.

This PR adopts the optimistic, "assume it's done" UX requested by NicolasBonet:

  • Reads isOffline via useNetwork().
  • Decouples the Save button from isSaving while offline: isLoading={isSaving && !isOffline} and isDisabled={hasHtmlTag || (isSaving && !isOffline)}. The online flow is unchanged.
  • Moves the Button inside the existing OfflineWithFeedback wrapper so the queued-state styling and the onClose error dismiss apply to the whole interaction (no duplicate error row).
  • When handleSave runs while offline, immediately fires the existing "Saved" confirmation. The shared logic was extracted into a small triggerSavedConfirmation callback used by both the offline path and the existing online effect.

Fixed Issues

$ #92032
PROPOSAL: #92032 (comment)

Tests

  1. Go to Account > Profile.
  2. Open account switcher.
  3. Select the agent.
  4. Edit AI prompt on Profile and click Save.
  5. The prompt should be saved
  • Verify that no errors appear in the JS console

Offline tests

  1. Sign in with an Expensifail account and create an agent on Account > Agents.
  2. Go to Account > Profile and switch to the agent via the account switcher.
  3. Go offline.
  4. Edit the AI prompt text and tap Save.
  5. Verify the Save button is not disabled, does not show an infinite spinner, and briefly shows the "Saved" confirmation with the checkmark icon.
  6. Verify the offline/queued styling (OfflineWithFeedback) is shown around the prompt area while the action is pending.
  7. Reconnect and verify the request is replayed without errors and no console errors appear.

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

MacOS: Chrome / Safari
Screen.Recording.2026-05-29.at.12.23.42.PM.mov
iOS Native
Screen.Recording.2026-05-29.at.12.32.59.PM.mov

Offline:

Screen.Recording.2026-06-01.at.2.19.10.PM.mov

Co-authored-by: Nicolás Bonet <NicolasBonet@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
...rc/pages/settings/Profile/AgentAIPromptSection.tsx 81.72% <100.00%> (+2.17%) ⬆️
... and 8 files with indirect coverage changes

@NicolasBonet NicolasBonet marked this pull request as ready for review May 29, 2026 17:25
@NicolasBonet NicolasBonet requested a review from a team as a code owner May 29, 2026 17:25
@melvin-bot melvin-bot Bot requested review from Krishna2323 and flaviadefaria and removed request for a team May 29, 2026 17:25
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 29, 2026

@Krishna2323 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot melvin-bot Bot requested review from a team, NicolasBonet and Ollyws and removed request for a team May 29, 2026 17:25
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented May 29, 2026

@Ollyws @NicolasBonet One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@NicolasBonet
Copy link
Copy Markdown
Contributor

@Ollyws I am the author, so will leave this one for you

Comment thread src/pages/settings/Profile/AgentAIPromptSection.tsx
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee8a77d1ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pages/settings/Profile/AgentAIPromptSection.tsx Outdated
@parasharrajat
Copy link
Copy Markdown
Member

I will review this as it is part of the original issue.

@NicolasBonet
Copy link
Copy Markdown
Contributor

@Expensify/design guys could you confirm this is the intended behavior when we are offline? I added a video in the first post

@dannymcclain
Copy link
Copy Markdown
Contributor

I think what you're showing in the video makes sense to me, but I would love a gut check from the rest of @Expensify/design.

@shawnborton
Copy link
Copy Markdown
Contributor

Once the value is saved, I think it's fine if the textarea has reduced opacity but I don't think the Save button would get reduced opacity.

And can we add a little margin (maybe 12px) above this error message and the save button?
CleanShot 2026-06-01 at 17 18 18@2x

@NicolasBonet
Copy link
Copy Markdown
Contributor

@MelvinBot could you implement: #92102 (comment)

Wrap only the prompt text field in OfflineWithFeedback so the queued/faded
styling applies to the textarea but not the Save button. Render the error row
via a standalone ErrorMessageRow below the button with a 12px top margin, and
give the button a 12px gap above it.

Co-authored-by: Nicolás Bonet <NicolasBonet@users.noreply.github.com>
@MelvinBot MelvinBot requested a review from a team as a code owner June 1, 2026 15:57
@melvin-bot melvin-bot Bot requested review from bernhardoj and removed request for a team June 1, 2026 15:57
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Jun 1, 2026

@bernhardoj Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@MelvinBot
Copy link
Copy Markdown
Contributor Author

Done in 0a1e1aa — both points addressed:

  • Save button no longer fades while offline. Only the prompt text field is wrapped in OfflineWithFeedback now, so the queued/translucent styling applies to the textarea while the Save button stays full‑opacity (and isn't stuck disabled or spinning).
  • Spacing: added a 12px gap above the Save button (mb3 on the text field) and a 12px gap above the error row (mt3 on the standalone ErrorMessageRow). The error row still renders below the button and is still dismissible.

See AgentAIPromptSection.tsx:188-219.

Verified in the browser: offline, the text field fades to ~0.5 opacity while the Save button stays at full opacity (not disabled), and the gaps measure ~12px above both the button and the error row. npm test for the related suites (AgentActionTest, EditPromptPageTest, ProfilePageTest) passes (59/59), and the component passes the React Compiler check.

@MelvinBot
Copy link
Copy Markdown
Contributor Author

⚠️ Something went wrong. This may be a transient issue — try again. If it persists, check status.anthropic.com.

Run details

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

🚧 @NicolasBonet has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

🚧 @NicolasBonet has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
Built from App PR #92102.

Android 🤖 iOS 🍎
⏩ SKIPPED ⏩ ⏩ SKIPPED ⏩
The build for Android was skipped The build for iOS was skipped
Web 🕸️
https://92102.pr-testing.expensify.com
Web

👀 View the workflow run that generated this build 👀

@NicolasBonet
Copy link
Copy Markdown
Contributor

@MelvinBot there is an issue, when offline I still can modify the input and click save again, but if I do there is no feedback and when connection is back we see only the first edit going though.

NicolasBonet and others added 2 commits June 1, 2026 14:11
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers the case where a queued offline save keeps pendingAction=update
(isSaving true) and a second offline edit must still call updateAgentPrompt
rather than being silently dropped.

Co-authored-by: Nicolás Bonet <NicolasBonet@users.noreply.github.com>
@MelvinBot
Copy link
Copy Markdown
Contributor Author

Good catch NicolasBonet — confirmed and addressed.

Root cause: handleSave bailed out early on if (isSaving). Offline, the optimistic write sets pendingAction = UPDATE and that can't resolve until reconnect, so isSaving stays true for the whole offline period. A second tap on Save hit that guard and returned early — the new edit was never queued (hence no "Saved" feedback), and on reconnect only the first queued request replayed.

Fix (already on the branch): the guard now skips while offline — if (isSaving && !isOffline) — matching the same pattern already used for the button's isLoading/isDisabled. Offline edits are now each queued in order, the "Saved" confirmation fires every time, and on reconnect the requests replay FIFO so the latest edit wins.

I also added a regression test for exactly this scenario (queued save still pending → second offline edit must still call updateAgentPrompt): ProfilePageTest.tsx:346. Full suite passes (14/14).

@NicolasBonet
Copy link
Copy Markdown
Contributor

NicolasBonet commented Jun 1, 2026

@shawnborton:

Offline mode

Screen.Recording.2026-06-01.at.2.19.10.PM.mov

With error

image

@MelvinBot
Copy link
Copy Markdown
Contributor Author

The failing check is unrelated to this PR — it's a known flaky test, so I'm not pushing a code fix.

The only failing check is test (job 6), and the failure is in tests/unit/MiddlewareTest.ts:154 (Middleware › HandleUnusedOptimisticID › Request with preexistingReportID) — expect(global.fetch).toHaveBeenCalledTimes(2) received 3. This is a timing-dependent flake already tracked in #90660 and has been failing on main itself (#92104, #92107).

This PR only changes the AI prompt profile UI (AgentAIPromptSection.tsx) and its UI test (ProfilePageTest.tsx) — nothing in the API/middleware/network layer that MiddlewareTest exercises. The PR's own tests/ui/ProfilePageTest.tsx passed, as did all 7 other test shards and every other check.

Recommended action: re-run the failed test (job 6) job (Actions → the failed run → "Re-run failed jobs"). It should pass on retry.

Evidence
  • Failure: Expected number of calls: 2 / Received number of calls: 3 at tests/unit/MiddlewareTest.ts:154, in suite Middleware › HandleUnusedOptimisticID › Request with preexistingReportID.
  • Shard result: Test Suites: 1 failed, 1 skipped, 97 passed; Tests: 1 failed, 144 skipped, 1773 passed.
  • Files changed in this PR: src/pages/settings/Profile/AgentAIPromptSection.tsx, tests/ui/ProfilePageTest.tsx — no overlap with src/libs/Middleware/API code.
  • Known flaky tracker: [$50] Flaky test: MiddlewareTest › HandleUnusedOptimisticID - fetch call count assertion fails intermittently #90660 ([$50] Flaky test: MiddlewareTest › HandleUnusedOptimisticID - fetch call count assertion fails intermittently).

@shawnborton
Copy link
Copy Markdown
Contributor

Nice, thanks!

@NicolasBonet NicolasBonet requested review from parasharrajat and removed request for Ollyws June 1, 2026 19:50
@NicolasBonet
Copy link
Copy Markdown
Contributor

@parasharrajat please review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants